<table id="priceTable" style="height:100%;" data-options="">
</table>
				<div id="tb" style="height: auto">
					机构: 
					<input id="organ" type="text" readonly style="width: 200px; height: 32.4px; padding-left: 10px;" onclick="showMenu(); return false;" class="textbox" value="${curOrgan.name! }"/>
					<input id="organIds" type="hidden" value="${curOrgan.ids! }">
					价格表:<input id="priceIds" name="priceIds" class="easyui-combobox theme-textbox-radius" style="width:200px;">
					
					<% if(authUrl("/productPriceSet/toAddPrice")){ %>
				<!-- 	<a id="add" href="#" onclick='addPrice()' class="easyui-linkbutton" iconCls="icon-add" >添加</a> -->
					<% } %>
					<% if(authUrl("/productPriceSet/toUpdatePrice")){ %>
					<a id="edit" href="#" onclick='upPrice()' class="easyui-linkbutton" iconCls="icon-edit">修改</a>
					<% } %>
					
					
				</div>
					<script>
// 						function searchPrice(){
// 							var priceIds = $("#priceIds").val();
// 							if(priceIds == "" || typeof(priceIds)=="undefined" || priceIds == '-1'){
// 								priceIds = "0";
// 							}
// 							var param = {
// 										'_query.priceIds':priceIds
// 							};
// 							$("#priceTable").datagrid('load', param);
// 						}
						function addPrice(){
							var organIds = $("#organIds").val();
							var url = 'productPriceSet/toAddPrice?organIds=' + organIds;
							loadDialog($('#priceTable'), $('#priceIds'), '添加产品价格表', url);
						}
						function upPrice(){
							var priceIds = $("#priceIds").val();
							var organIds = $("#organIds").val();
							
							if(priceIds == -1){
								 $.slideMsg("请选择要修改的价格表！", parent.$);
							}else{
								
								$.post("productPriceSet/cjPrice",{priceIds:priceIds,organIds:organIds},function(date){
									if(date=='1'){
										var url = 'productPriceSet/toUpdatePrice?priceIds=' + priceIds + '&organIds=' + organIds;
										loadDialog($('#priceTable'), $('#priceIds'), '修改产品价格表', url);
									}else{
										$.alert(parent.$, "通用价格表,不可修改！");
									}
								})
								
							}
						}
						
						function initPriceTable(){
							var childGridId = "${childGridId}";
							var $childGrid = $("#" + childGridId);
							var priceIds = $("#priceIds").val();
							if(priceIds == "" || typeof(priceIds)=="undefined" || priceIds == '-1'){
								priceIds = "0";
							}
							var param = {
										'_query.priceIds':priceIds
									};

							$('#priceTable').datagrid({
								cls: "theme-datagrid",
								toolbar: '#tb',
								singleSelect: true,
								rownumbers: true, //显示序号
								pagination: true,
								pageSize: 20,
								url: "productPriceSet/productPriceList",
								queryParams: param,
							    method: 'post',
								collapsible: true,
								columns:[[
								  		{field:'ids',title:'ids',width:100,align:'center', hidden:true},
								  		{field:'ppids',title:'ppids',width:100,align:'center', hidden:true},
								  		{field:'probh',title:'编号',width:100,align:'center'},
								  		{field:'name',title:'名称',width:150,align:'center'},
								  		{field:'type',title:'类型',width:100, align:'center'},
								  		{field:'putprice',title:'入库价(元)',width:80, align:'center'},
								  		{field:'outprice',title:'出库价(元)',width:80, align:'center'},
								  		{field:'priceids',title:'priceIds',width:160, align:'center', hidden:true}
								      ]],
								onLoadSuccess:function(){
									$('#priceTable').datagrid("selectRow", 0);
									var gridSelectRow = $("#priceTable").datagrid('getSelected');
									if (typeof(gridSelectRow) == "undefined") { 
						        		$childGrid.datagrid({ 
						        			cls: "theme-datagrid",
						        			rownumbers: false,
											title: " ",
											columns:[[]]
						        		});
						        	}else{
						        		var priceIds = gridSelectRow.priceids;
						        		var productIds = gridSelectRow.ids;
						        		var name = gridSelectRow.name + "历史价";
							        	$childGrid.datagrid({
											cls: "theme-datagrid",
											title: name,
											singleSelect: true,
											rownumbers: true, //显示序号
											pagination: true,
											pageSize: 10,
											url: "productPriceSet/oldPriceList",
											queryParams: {
												'_query.priceIds': priceIds,
												'_query.productIds':productIds
											},
										    method: 'post',
											collapsible: true,
											columns:[[
											  		{field:'name',title:'名称',width:150,align:'center'},
											  		{field:'putprice',title:'入库价(元)',width:100, align:'center'},
											  		{field:'outprice',title:'出库价(元)',width:100, align:'center'},
											  		{field:'starttime',title:'开始时间',width:160, align:'center'},
											  		{field:'disabletime',title:'停用时间',width:160, align:'center'}
											      ]]
										});
						        	}
								},
								onClickRow:function(rowIndex,rowData){
									$childGrid.datagrid({title: rowData.name + "历史价"});
									$childGrid.datagrid('load',{
										"_query.priceIds": rowData.priceids,
										"_query.productIds": rowData.ids
									});
								}
							});
						}
						
						function initPriceSelect(organIds){
							var url;
							if(organIds == "" || typeof(organIds)=="undefined"){
								url = "productPriceSet/priceSelect";
							}else{
								url = 'productPriceSet/priceSelect?organIds=' + organIds;
							}
							$.post(url, function(data) {
								data.unshift({  
				                     'ids': '-1',  
				                     'name': '-请选择-'  
				                 });
								$('#priceIds').combobox({
									 data:data,
								    valueField:'ids',
								    textField:'name',
								    onLoadSuccess : function(){  
								    	 var val = $(this).combobox('getData');  
			                                for (var item in val[0]) {  
			                                    if (item == 'ids') {  
			                                        $(this).combobox('select', val[0][item]);  
			                                    }  
			                                }
// 			                                initPriceTable();
							        },
							        onChange:function(n,o){
							        	/* if(n=='e0482432bb4045c98e93aef18c86f83c'||n=='f8f692025b9f456084742f586d1efe5e'||n=='fd2cdaf946524d5997afa7af8eaa180d'){
							        			document.getElementById("add").style.display="inline-block";
							        			document.getElementById("edit").style.display="inline-block";
							        			
							        		
							        	} */
										initPriceTable();
									}
								});
							});
							
						}
						$(function() {
							initPriceSelect();
						})
					</script>